package com.situ.controller;

import com.situ.domain.entity.TDictDistrict;
import com.situ.service.AreaService;
import com.situ.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/area")
@RequiredArgsConstructor
@Tag(name = "地区接口")
public class AreaController {


    private final AreaService areaService;

    @GetMapping("/getProvinceList")
    @Operation(summary = "获取省份列表")
    public Result getProvinceList() {
        List<TDictDistrict> list = areaService.lambdaQuery()
                .eq(TDictDistrict::getParent, "86")
                .list();
        return Result.success(200, "查询成功", list);
    }

    @GetMapping("/getCityList")
    @Operation(summary = "获取城市列表")
    public Result getCityList(String provinceCode) {
        List<TDictDistrict> list = areaService.lambdaQuery()
                .eq(TDictDistrict::getParent, provinceCode)
                .list();
        return Result.success(200, "查询成功", list);
    }

    @GetMapping("/getDistrictList")
    @Operation(summary = "获取地区列表")
    public Result getDistrictList(String cityCode) {
        List<TDictDistrict> list = areaService.lambdaQuery()
                .eq(TDictDistrict::getParent, cityCode)
                .list();
        return Result.success(200, "查询成功", list);
    }

}
